package org.wiztools.commons.feed;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public final class FeedUtil {
    private FeedUtil(){}

    public static List<FeedEntry> sortFeed(final List<Feed> feeds){
        List<FeedEntry> entries = new ArrayList<FeedEntry>();
        for(Feed feed: feeds){
            entries.addAll(feed.getEntries());
        }
        sortFeedEntries(entries);
        return entries;
    }

    public static void sortFeedEntries(final List<FeedEntry> feedEntries){
        Collections.sort(feedEntries, new Comparator<FeedEntry>() {
            public int compare(FeedEntry entry1, FeedEntry entry2) {
                return entry1.getPublishedDate().compareTo(entry2.getPublishedDate()) * -1;
            }
        });
    }
}
